package org.quickstep.application.action;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;

/**
 * 
 * Action which acts as list of actions 
 * 
 * @author exr0bs5
 *
 */
public class ActionGroup extends ArrayList<Action> implements IActionGroup {

	private static final long serialVersionUID = 1L;
	
	private final Action action;	
	
	public ActionGroup( String name, Icon icon ) {
		 action = createAction(name, icon);
	}
	
	public ActionGroup( String name ) {
		action = createAction(name, null);
	}
	
	private static Action createAction( String name, Icon icon ) {
		return new AbstractAction(name,icon) {
			private static final long serialVersionUID = 1L;
			@Override
			public void actionPerformed(ActionEvent e) {}
		};
	}
	
	public ActionGroup( String name, Collection<Action> actions) {
		action = createAction(name, null);
		if ( actions != null ) {
			addAll( actions );
		}
	}

	public ActionGroup( String name, Action... actions) {
		this( name, Arrays.asList(actions) ); 
	}


	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		action.addPropertyChangeListener(listener);
	}

	@Override
	public Object getValue(String key) {
		return action.getValue(key);
	}

	@Override
	public boolean isEnabled() {
		return action.isEnabled();
	}

	@Override
	public void putValue(String key, Object value) {
		action.putValue(key, value);
	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		action.removePropertyChangeListener(listener);
	}

	@Override
	public void setEnabled(boolean enabled) {
		action.setEnabled(enabled);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		action.actionPerformed(e);
	}

}
